package jfb.examples.gmf.filesystem.diagram.part.transform;

import jfb.examples.gmf.filesystem.diagram.part.FilesystemDiagramEditorPlugin;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.diagram.ui.actions.AbstractDeleteFromAction;
import org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
import org.eclipse.ui.IWorkbenchPart;

public class TransformationAction extends DiagramAction {
	public Transformation mTransformation;
	
    public TransformationAction(IWorkbenchPart part, Transformation transformation) {
		super(part);
		mTransformation = transformation;
	}
	
	public void init() {
		super.init();
		setId(mTransformation.mDescription);
		setText(mTransformation.mDescription);
		setToolTipText(mTransformation.mDescription);
	}

	
	protected String getCommandLabel() {
		return mTransformation.mDescription;
	}

	protected Command getCommand(Request request) {
		return new TransformationCommand(mTransformation);
	}
		
		
     public class TransformationCommand extends Command {
    	 public Transformation mTransformation;
    	 
         public TransformationCommand(Transformation transformation) {
        	 mTransformation = transformation;
         }
    	 
    	 public void execute() {
    		 // TODO: perform save!!!
    		 // FilesystemDiagramEditorPlugin.getInstance().doSave();
    		 // TODO: get ecore diag file
    		 // TODO: perform transformation
    		 FilesystemDiagramEditorPlugin.getInstance().logInfo("Execute transformation " + mTransformation.mDescription + 
    				 ". Object: " + ((GraphicalEditPart)getSelectedObjects().get(0)).getModel()
    				 + ". ID: " + EMFCoreUtil.getProxyID((EObject)(((GraphicalEditPart)getSelectedObjects().get(0)).getModel())));
    	 }
    	 
     }


	@Override
	protected Request createTargetRequest() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected boolean isSelectionListener() {
		// TODO Auto-generated method stub
		return false;
	}
}
